fix respond() & readystatechange process flow #184
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose
Fix the process flow where a
readystatechange
event should not be triggered afterloadend
event. When it does, it is incompatible with some network lib(likenatty-fetch
) stated in issue #165.I found that the code was using fall through logic which caused the extra readystatechange event to be thrown after the loadend event inside of the
readyStateChange()
function. There was logic added to delineate from a finished XHR request and throw the loadend but not to stop processing the fall through logic. I added a return statement to prevent the drop through but note that a readystatechange did have to be added prior to the loadend otherwise some requests would not resolve and it was noticeable through other unit-tests.I added 1 unit test to replicate the issue results.
Resolves: #165
How to verify
npm install
git reset --hard HEAD~1
npm test
. This branch includes 1 new unit test to accompany the error so during this test run 1 of the tests will fail.git pull
npm test
again. All tests will pass verifying there was no regression and the buggy scenarios were fixed.